#******************** (C) COPYRIGHT 2005 STMicroelectronics ********************
#* File Name          : 91x_vect.s
#* Author             : MCD Application Team
#* Date First Issued  : 10/25/2005 :  Beta Version V0.1
#* Description        : This File used to initialize the exception and IRQ
#*                      vectors, and to enter/return to/from exceptions
#*                      handlers.
#*******************************************************************************


        .extern   __program_start
        .extern   vPortYieldProcessor
        .extern   EXC_Undef
        .extern   EXC_PrefAbt
        .extern   EXC_DataAbt
        .extern   FIQHandler

        .include  "ISR_Support.inc"



#*******************************************************************************
#                        Exception vectors
#*******************************************************************************
        .section .vectors, "ax"
	.code 32
	.align  0

        LDR     PC, Reset_Addr
        LDR     PC, Undefined_Addr
        LDR     PC, SWI_Addr
        LDR     PC, Prefetch_Addr
        LDR     PC, Abort_Addr
        NOP
        B       IRQHandler
        LDR     PC, FIQ_Addr

#*******************************************************************************
#               Exception handlers address table
#*******************************************************************************

Reset_Addr:      .word     __program_start
Undefined_Addr:  .word     EXC_Undef
SWI_Addr:        .word     vPortYieldProcessor
Prefetch_Addr:   .word     EXC_PrefAbt
Abort_Addr:      .word     EXC_DataAbt
                 .word     0
IRQ_Addr:        .word     IRQHandler
FIQ_Addr:        .word     FIQHandler



#*******************************************************************************
#                         Exception Handlers
#*******************************************************************************





#*******************************************************************************
#* Function Name  : IRQHandler
#* Description    : This function called when IRQ exception is entered.
#* Input          : none
#* Output         : none
#*******************************************************************************

.set VectorAddress,          0xFFFFF030  // VIC Vector address register address.
.set VectorAddressDaisy,     0xFC000030  // Daisy VIC Vector address register

IRQHandler:
   portSAVE_CONTEXT              // Save the context of the current task.

   LDR    r0, = VectorAddress
   LDR    r0, [r0]                  // Read the routine address
   LDR    r1, = VectorAddressDaisy
   LDR    r1, [r1]
   MOV    lr, pc
   BX     r0
   LDR    r0, = VectorAddress       // Write to the VectorAddress to clear the
   STR    r0, [r0]                  // respective interrupt in the internal interrupt
   LDR    r1, = VectorAddressDaisy  // Write to the VectorAddressDaisy to clear the
   STR    r1,[r1]                   // respective interrupt in the internal interrupt

   portRESTORE_CONTEXT              // Restore the context of the selected task.








